<?php
use think\facade\Request;
use think\facade\Route;
use app\common\ArrayFunction;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/18
 * Time: 13:39
 */
/**
 * @param $title
 * @param $field
 * @param $value
 * @param string $attr
 *
{:html_upload_one('图片上传','single_pic',$info,['180','180'],false)}
{:html_upload_many('品牌主图','multi_pic',$info,['180','180'],true)}
 */
function html_number($title,$field, $value, $default = 100)
{
    $param = Request::param();
//    if(!empty(input('type_id'))) echo '';
    $value = isset($value) && !empty($value) ? $value[$field] : $default;
    //if(Request::action() == 'create'){$value = 1000;}
    $html = <<<EOT
<div class="item form-group">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="{$field}">{$title} <span class="required">*</span>
                    </label>
                    <div class="col-md-6 col-sm-6 col-xs-12 ">
                      <input type="number" id="{$field}" name="{$field}" value="{$value}" required min="0" class="form-control col-md-7 col-xs-12" placeholder="">
                    </div>
                  </div>
EOT;
    //if(!empty(input('type_id'))) $html = '';
    echo $html;
}

function html_sort($title,$field, $value, $default = 100)
{
    $param = Request::param();
//    if(!empty(input('type_id'))) echo '';
    $value = isset($value) && !empty($value) ? $value[$field] : $default;
    //if(Request::action() == 'create'){$value = 1000;}
    $html = <<<EOT
<div class="item form-group">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="{$field}">{$title} <span class="required">*</span>
                    </label>
                    <div class="col-md-6 col-sm-6 col-xs-12 ">
                      <input type="number" id="{$field}" name="{$field}" value="{$value}" required min="0" class="form-control col-md-7 col-xs-12" placeholder="">
                    </div>
                  </div>
EOT;
    //if(!empty(input('type_id'))) $html = '';
    echo $html;
}
/**
 * input='text'表单
 * @param $title
 * @param $field
 * @param string $value
 * @param string $attr
 */
function html_text($title,$field, $value = '', $maxlength = 100,$minlength=1,$required = 'required'){

    $value = isset($value) && !empty($value) ? $value[$field] : '';
//    $input_validate = config('app.input_validate');
//    if(!empty($required)) $required = 'required';

    $html = <<<EOF
<div class="item form-group">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="{$field}">{$title} <span class="required">*</span>
                    </label>
                    <div class="col-md-6 col-sm-6 col-xs-12 ">
                      <input type="text" id="{$field}" name="{$field}" value="{$value}" minlength="{$minlength}" maxlength="{$maxlength}" {$required} class="form-control col-md-7 col-xs-12" placeholder="">
                    </div>
                  </div>
EOF;
    echo $html;
}

/*
 * 地址
 */
function html_address($title,$field, $value = '', $maxlength = 100,$minlength=1,$required = 'required'){


    $lng = isset($value) && !empty($value['lng']) ? $value['lng'] : '';
    $lat = isset($value) && !empty($value['lat']) ? $value['lat'] : '';
    $value = isset($value) && !empty($value) ? $value[$field] : '';
//    $input_validate = config('app.input_validate');
//    if(!empty($required)) $required = 'required';

    $html = <<<EOF
<div class="form-group">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="{$field}">{$title} <span class="required">*</span>
                    </label>
                    <div class="col-md-4 col-sm-4 col-xs-12 ">
                      <input type="text" id="{$field}" name="{$field}" value="{$value}" minlength="{$minlength}" maxlength="{$maxlength}" {$required} class="form-control col-md-7 col-xs-12" placeholder="">
                    </div>
                    <div class="col-md-1 col-sm-1 col-xs-12 ">
                      <input type="text" id="lng" name="lng" value="{$lng}"  readonly class="form-control col-md-7 col-xs-12" placeholder="">
                    </div>
                    <div class="col-md-1 col-sm-1 col-xs-12 ">
                      <input type="text" id="lat" name="lat" value="{$lat}"  readonly class="form-control col-md-7 col-xs-12" placeholder="">
                    </div>
                  </div>


EOF;
    echo $html;
}

function html_map(){
    $html = <<<EOF
 <div class="form-group">
                    <label class="col-sm-3 control-label" for="area"></label>
                    <div id="container" style="width: 772px;height: 400px; left: 10px;"></div>
                </div>
EOF;
    echo $html;


}

function html_datetime($title,$field, $value = '', $required = 'required'){

//    $value = (isset($value) && !empty($value) ? $value[$field] : $field == 'create_time') ? date('Y-m-d H:i:s') : '';
   if(empty($value)){ //空数据或者空值
       $value = ''; //给前台空字符串
       if($field == 'create_time'){
           $value = date('Y-m-d H:i:s');
       }
   }else{
        //给值了 但是是0000 那转换成空
       if($value[$field] == '0000-00-00 00:00:00'){
           $value = ' ';
       }else{
           $value = $value[$field];
       }

   }

//    $input_validate = config('app.input_validate');
//    if(!empty($required)) $required = 'required';

    $html = <<<EOF
<div class="item form-group">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="{$field}">{$title}<span class="required" aria-required="true">*</span>
                    </label>
                    <div class="col-md-6 col-sm-6 col-xs-12 ">
                        <input {$required} type="text" autocomplete="off" name="{$field}" value="{$value}"  class="year form-control col-md-7 col-xs-12" placeholder="">
                    </div>
                </div>
EOF;
    echo $html;
}

function html_text2($title,$field, $value = '', $model,$maxlength = 100,$minlength=2,$required = 'required'){

    $value = isset($value) && !empty($value) ? $value[$model] : '';
//    $input_validate = config('app.input_validate');
//    if(!empty($required)) $required = 'required';

    $html = <<<EOF
<div class="item form-group">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="{$field}">{$title} <span class="required">*</span>
                    </label>
                    <div class="col-md-6 col-sm-6 col-xs-12 ">
                      <input type="text" id="{$field}" name="{$field}" value="{$value}" minlength="{$minlength}" maxlength="{$maxlength}" {$required} class="form-control col-md-7 col-xs-12" placeholder="">
                    </div>
                  </div>
EOF;
    echo $html;
}
function html_textarea($title,$field, $value = '',$placeholder='',$required = 'required'){
    $value = isset($value) && !empty($value) ? $value[$field] : '';
//    $input_validate = config('app.input_validate');
//    if(!empty($required)) $required = 'required';

    $html = <<<EOF
<div class="item form-group">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="{$field}">{$title} <span class="required">*</span>
                    </label>
                    <div class="col-md-6 col-sm-6 col-xs-12 ">
                      <textarea  placeholder="{$placeholder}"
                      style="height: 92px;" type="text" id="{$field}" name="{$field}"   class="form-control col-md-7 col-xs-12" placeholder="">{$value}</textarea>
                    </div>
                  </div>
EOF;
    echo $html;
}


function html_password($title,$field, $value = '', $maxlength = 100,$required = 'required'){
    $value = isset($value) && !empty($value) ? $value[$field] : '';
//    $input_validate = config('app.input_validate');
//    if(!empty($required)) $required = 'required';

    $html = <<<EOF
<div class="item form-group">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="{$field}">{$title} <span class="required">*</span>
                    </label>
                    <div class="col-md-6 col-sm-6 col-xs-12 ">
                      <input type="password" id="{$field}" name="{$field}" value="{$value}" minlength="2" maxlength="{$maxlength}" {$required} class="form-control col-md-7 col-xs-12" placeholder="">
                    </div>
                  </div>
EOF;
    echo $html;
}


/**单选按钮
 * @param string $title
 * @param $field
 * @param $value 字段值
 * @param bool $is_validator
 * @param $text
 * @param $i_val 从几开始start
 */
function html_radio($title = 'hidden', $field, $value, $args ,$i_val = 1)
{

    $value = isset($value) && !empty($value) && !empty($value[$field]) ? $value[$field] : $i_val;//把数组的值转成单一当前要用的值 $value[$field]用户切换不提交数据使用
    $checked = $checked1 = $checked2 = '';
//    if($value == 1) $checked1 = 'checked';
//    if($value == 2) $checked2 = 'checked';
    $level = ArrayFunction::level($args);//获取几维数组;
    if($title != 'hidden'){
        $str = '';
        //$array = explode('|',$text);
        //for ($i = 1; $i < count($text)+1; $i++){ //只支持 0 1 2 格式
         foreach ($args as $k => $v){
            if($level == 2){
                $checked = '';
                if(\request()->action() == 'update'){
                    if($value == $v['id']){ //用于修改的时候选中
                        $checked = 'checked';
                    }
                }else{
                    //添加的时候第一项
                    if($k+1 == $i_val){ //第几项key选中
                        $checked = 'checked';
                    }
                }

                $str .= "<div class=\"radio icheck-turquoise\" style=\"display: inline-block\">
                          <input type=\"radio\"  {$checked} id=\"{$field}_{$k}\" name=\"{$field}\" value=\"{$v['id']}\">
                          <label for=\"{$field}_{$k}\" >{$v['title']}</label>
                        </div>";
            }else{
                $checked = '';
                if($value == $k){ //用于修改的时候选中
                    $checked = 'checked';
                }
                $str .= "<div class=\"radio icheck-turquoise\" style=\"display: inline-block\">
                          <input type=\"radio\"  {$checked} id=\"{$field}_{$k}\" name=\"{$field}\" value=\"{$k}\">
                          <label for=\"{$field}_{$k}\" >{$args[$k]}</label>
                        </div>";
            }

        }
        $html = <<<EOF
<div class="item form-group">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12">{$title} <span class="required">*</span>
                    </label>
                    <div class="col-md-6 col-sm-6 col-xs-12 ">
                      <div  class="col-md-6 col-sm-6 col-xs-12 ">
                        {$str}
                      </div>
                    </div>
                  </div>
EOF;
        echo $html;
    }

}
/*
 * 多选按钮
 */
function html_checkbox($title = 'hidden', $field, $value, $args ,$i_val = 1)
{

    $value = isset($value) && !empty($value) && !empty($value[$field]) ? $value[$field] : $i_val;//把数组的值转成单一当前要用的值 $value[$field]用户切换不提交数据使用
    $checked = $checked1 = $checked2 = '';
//    if($value == 1) $checked1 = 'checked';
//    if($value == 2) $checked2 = 'checked';
    $level = ArrayFunction::level($args);//获取几维数组;
    if($title != 'hidden'){
        $str = '';
        //$array = explode('|',$text);
        //for ($i = 1; $i < count($text)+1; $i++){ //只支持 0 1 2 格式
        foreach ($args as $k => $v){

            if($level == 2){
                $checked = '';
                if(\request()->action() == 'update'){
                    $value2 = explode(',', $value);
                    if(in_array($v['id'],$value2)){ //用于修改的时候选中
                        $checked = 'checked';
                    }
                }else{
                    //添加的时候第一项
                    $checked = '';
                }
                $str .= "<div class=\"radio icheck-turquoise\" style=\"display: inline-block\">
                          <input required type=\"checkbox\"  {$checked} id=\"{$field}_{$k}\" name=\"{$field}[]\" value=\"{$v['id']}\">
                          <label for=\"{$field}_{$k}\" >{$v['title']}</label>
                        </div>";
            }else{
                $checked = '';
                if($value == $k){ //用于修改的时候选中
                    $checked = 'checked';
                }
                $str .= "<div class=\"radio icheck-turquoise\" style=\"display: inline-block\">
                          <input type=\"checkbox\"  {$checked} id=\"{$field}_{$k}\" name=\"{$field}[]\" value=\"{$k}\">
                          <label for=\"{$field}_{$k}\" >{$args[$k]}</label>
                        </div>";
            }

        }
        $html = <<<EOF
<div class="item form-group">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12">{$title} <span class="required">*</span>
                    </label>
                    <div class="col-md-6 col-sm-6 col-xs-12 ">
                      <div  class="col-md-6 col-sm-6 col-xs-12 ">
                        {$str}
                      </div>
                    </div>
                  </div>
EOF;
        echo $html;
    }

}
function html_upload_one2($title,$field = 'single_pic',$pic_value = '',$size)
{

    $controller = Request::controller(true);
    $action = Request::action();
    $default = "/static/console/default.png";

    $pattern = '/(?:\()(.*)(?:\))/i';
    preg_match($pattern,$title,$match);
    $width = 150;
    if(!empty($match)){
        $w = explode('x',$match[1])[0];
        $h = explode('x',$match[1])[1];
        $width = 150*$w/$h;
    }
    $src = isset($pic_value[$field]) && !empty($pic_value[$field]) ? thumbWater($pic_value[$field],$size[0],$size[1]) : $default;
    $value = isset($pic_value[$field]) && !empty($pic_value[$field]) ? $pic_value[$field] : '';
    if($title != false){
//        $pic_value = $pic_value ? "/uploads/{$controller}/{$pic_value}" : "/static/console/default.png";
        $require = $action == 'create' ? 'required' : '';//修改不需要验证
        $html = <<<EOT
        
<div class="item form-group">
                    <label  class="control-label col-md-3 col-sm-3 col-xs-12" for="{$field}">{$title} <span class="required" aria-required="true">*</span>
                    </label>
                    <div class="col-md-6 col-sm-6 col-xs-12 ">
                      <!-- bootstrap-imageupload. -->
                      <div class="panel panel-default" style="overflow:hidden;zoom:1;">
                        <div data-am-widget="1gallery" class="am-gallery am-avg-sm-2
am-avg-md-3 am-avg-lg-4 am-gallery-overlay" data-am-gallery="{ pureview: true }"><div class="file-tab panel-body" id="imgdiv{$field}" style="display: inline-block;">
                        <input type="hidden" name="{$field}_url" value="{$value}" />
                        <img width="{$width}" height="150" id="imgShow{$field}" src="{$src}" alt="Image preview" class="thumbnail" style="">
                        <label class="btn btn-default">选择文件<input type="file" name="{$field}" id="up_img{$field}" style="display: none;" {$require}></label>
                        <label class="btn btn-default" onclick="rem(this)">移除文件</label></div></div>
                        </div>
                      </div>
                    </div>
                  <script>
                  var targetSetting = {
            UpBtn: "up_img{$field}",
            DivShow: "imgdiv{$field}",
            ImgShow: "imgShow{$field}",
            callback:this.callback
        };

        //配置文件使用递归的方式来处理
        new uploadPreview(targetSetting);
      
</script>
EOT;
        echo $html;
    }

}
/*
 * @param $title 左侧标题
 * @param string $field 上传的字段
 * @param string $pic_value update时候图片值
 * @pram string $is_validator 是否验证 默认验证
 * 单图上传函数
 */
function html_upload_one($title,$field = 'single_pic',$pic_value = '',$size)
{


    $controller = Request::controller(true);
    $action = Request::action();
    $default = "/public/static/console/default.png";

    $pattern = '/(?:\()(.*)(?:\))/i';
    preg_match($pattern,$title,$match);
    $width = 150;
    if(!empty($match)){
        $w = explode('x',$match[1])[0];
        $h = explode('x',$match[1])[1];
        $width = 150*$w/$h;
    }
   // $src = isset($pic_value[$field]) && !empty($pic_value[$field]) ? thumbWater($pic_value[$field],$size[0],$size[1]) : $default;
    $value = isset($pic_value[$field]) && !empty($pic_value[$field]) ? $pic_value[$field] : '';
    if($title != false){
//        $pic_value = $pic_value ? "/uploads/{$controller}/{$pic_value}" : "/static/console/default.png";
        $require = $action == 'create' ? 'required' : '';//修改不需要验证
        $html = <<<EOT
        
<div class="form-group">
<label class="col-sm-3 control-label">{$title}
                    </label>
          <div class="col-sm-6">
            <input id="{$field}" type="file" class="file-loading" >
            <input type="hidden" placeholder="缩略图" name="{$field}" value="{$value}" >
          </div>
        </div>

EOT;
        echo $html;
    }

}
/**
 * 多图上传
 * @param string $title
 * @param string $field
 * @param array $value
 * @param bool $is_validator
 * @param bool $is_hidden
 *
 */

function html_upload_many($title = 'hidden',$field = 'multi_pic',$value = [],$size){

    $value = isset($value) && !empty($value) ? $value[$field] : [];
    $str = '';

    if(!empty($value)){
        for ($key = 0 ; $key < count((array)$value) ; $key++){
            //$src = thumbWater($value[$key],$size[0],$size[1]);
            $str .= "<input type=\"hidden\" value=\"{$value[$key]['img']}\" name=\"temp_{$field}[]\" flag=\"{$value[$key]['info']}\" show=\"{$value[$key]['show']}\" >";
        }
    }
    $html = <<<EOF
<div class="form-group">
          <label class="col-sm-3 control-label">{$title}：</label>
          <div class="col-sm-6">
            <input id="{$field}" type="file" multiple>
            {$str}
          </div>
        </div>
EOF;
    echo $html;
}
function html_editor($title = '',$field = 'content' ,$value){
    $value = isset($value) && !empty($value) ? $value[$field] : '';
    $html = <<<EOF
 <div class="item form-group" style="overflow: auto;zoom:1;">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="{$field}">{$title} <span class="required"></span>
                    </label>
                    <div class="col-md-6 col-sm-6 col-xs-12 ">
                      <textarea type="text/plain" style="height: 300px;" id="containers_{$field}" name="{$field}" placeholder="请输入信息内容">{$value}</textarea>
                    </div>
                    </div>
EOF;
    echo $html;
}

/*
 * <div class="item form-group">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="parent_id">上级分类 <span class="required">*</span>
                    </label>
                    <div class="col-md-6 col-sm-6 col-xs-12">
                      <select name="parent_id" class="single_select js-states form-control" id="parent_id" style="width: 100%;">
                        <option value="0">| -- 顶级分类</option>
                        {volist name="list" id="item"}
                        <option value="{$item.id}" {eq name="item.id" value="$info.parent_id|default=''"}selected{/eq}{php}if(in_array($item['id'],isset($lower_level) ? $lower_level: []))echo 'disabled'{/php}>{php}echo str_repeat('&nbsp&nbsp&nbsp',$item['level']-1)."| -- ".$item['cat_name']{/php}</option>
                        {/volist}
                      </select>
                    </div>
                  </div>
 */
/**
 *  {:html_select('单位',$unit,$info,'unit_id','')}
 * @param $title 标题
 * @param array $list 循环二维数据
 * @param $value 详情$info值
 * @param int $field 主表的外键字段
 * @param string $required 控制是否必须选择
 */
function html_select($title, $field = 0, $value, $list = [], $required = 'required',$select_title = 'title')
{
    $value = isset($value) && !empty($value) ? $value[$field] : '0'; //$info['unit_id'];
    $option = '';

    //$list = getMenuTree($list);
    //需要id和title一致的时候 id起个别名

    $level = ArrayFunction::level($list);//获取几维数组;

    if (!empty($list)) {
        foreach ($list as $k => $v) {
            $selected = '';

            if ($level >= 2) {

                $get_forgine_id = \request()->get($field);//get外键id
                if ($get_forgine_id) {
                    $value = $get_forgine_id;
                }
                if ($v['id'] == $value) {
                    $selected = 'selected';
                }
                if ($field == 'member_id' || $field == 'son_id' || $field == 'parent_id') {
                    $is_member = $v['mobile'];
                }elseif($field == 'adminer_id'){
                    $is_member = $v['admin_name'];
                } else {
                    $is_member = $v[$select_title];
                }
//                if($select_title != 'title'){
//                    $is_member = $v['username'];
//                }
                $option .= "<option value=\"{$v['id']}\" {$selected}>" . $is_member . "</option>";
            } else { //一维数组就是自定义数组;
                if ($k == $value) {
                    $selected = 'selected';
                }

                $option .= "<option value=\"{$k}\" {$selected}>" . $v . "</option>";
            }

        }
    }

//    if(in_array($item['id'],isset($lower_level) ? $lower_level: []))echo 'disabled'{/php}>{php}echo str_repeat('&nbsp&nbsp&nbsp',$item['level']-1)."| -- ".$item['title']{/php}
    $html = <<<EOF
<div class="item form-group">
          <label class="control-label col-md-3 col-sm-3 col-xs-12" for="{$field}">{$title} <span class="required">*</span>
          </label>
          <div class="col-md-6 col-sm-6 col-xs-12">
            <select name="{$field}" {$required} class="single_select js-states form-control" id="{$field}" style="width: 100%;">
              <option value="">| -- 全部{$title}</option>
              {$option}
            </select>
          </div>
        </div>
EOF;
    echo $html;

}

/**
 *
 */
function html_select_many($title, $list = [], $value,$field = 0)
{
    $value = isset($value) && !empty($value) ? $value[$field] : '0';
    $option = '';

//    $list = getMenuTree($list);
    //需要id和title一致的时候 id起个别名

    if(!empty($list)){
        foreach ($list as $v) {
            $selected = '';

            if(\request()->action() == 'update'){

                $value2 = explode(',', $value);
                if(in_array($v['id'],$value2)){ //用于修改的时候选中
                    $selected = 'selected';
                }
            }else{
                //添加的时候第一项
                $checked = '';
            }
            if($field == 'member_id' || $field == 'son_id'){
                $is_member = $v['mobile'];
            }else{
                $is_member = $v['title'];
            }
            $option .= "<option value=\"{$v['id']}\" {$selected}>".$is_member."</option>";
        }
    }
//    if(in_array($item['id'],isset($lower_level) ? $lower_level: []))echo 'disabled'{/php}>{php}echo str_repeat('&nbsp&nbsp&nbsp',$item['level']-1)."| -- ".$item['title']{/php}
    $html = <<<EOF
<div class="item form-group">
          <label class="control-label col-md-3 col-sm-3 col-xs-12" for="{$field}">{$title} <span class="required">*</span>
          </label>
          <div class="col-md-6 col-sm-6 col-xs-12">
            <select required name="{$field}[]" class="multi_select js-states form-control" multiple="multiple"  id="{$field}" style="width: 100%;">
<!--            <option value="0">| &#45;&#45; 全部{$title}</option>-->
              {$option}
            </select>
          </div>
        </div>
EOF;
    echo $html;

}

function html_file($title,$field, $value = '', $maxlength = 100,$minlength=1,$required = 'required')
{
    $value = isset($value) && !empty($value) ? $value[$field] : '';
$html = <<<EOF
<div class="item form-group">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="{$field}">{$title} <span class="required" aria-required="true">*</span></label>
                    <div class="col-md-5 col-sm-5 col-xs-12 ">
                        <input type="text" id="{$field}" name="{$field}" value="{$value}"
                              class="form-control col-md-7 col-xs-12 valid" placeholder=""
                               aria-required="true" aria-invalid="false">
                    </div>
                    <div class="col-md-1 col-sm-1 col-xs-12 ">
                        <div id="thelist" class="uploader-list"></div>
                        <div id="{$field}_select" class="form-control-focus">选择文件</div>
                    </div>
                </div>
                <div class="item form-group">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12" > <span class="required" aria-required="true"></span></label>
                    <div class="col-md-6 col-sm-6 col-xs-12 ">
                        <!-- 进度条-->
                        <div id="{$field}_progress" class="progress-bar" role="progressbar" aria-valuenow="60"
                             aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
                            <!-- <span class="sr-only">60% 完成</span> -->
                        </div>
                    </div>
                </div>
EOF;
    echo $html;
}

function html_oss_file($title,$field, $value = '', $maxlength = 100,$minlength=1,$required = 'required'){
    $value = isset($value) && !empty($value) ? $value[$field] : '';
    $html = <<<EOF
<div class="form-group">
                    <label class="col-sm-3 control-label">{$title}：</label>
                    <div class="col-sm-4">
                        <input  type="text" id="{$field}" name="{$field}" class="form-control" placeholder=""
                               value="{$value}">
                    </div>
                    
                    <div class="col-sm-2">
                        <div id="{$field}">
                            <button id="{$field}_selectfiles" href="javascript:void(0);" class='btn btn-cyan'>选择文件</button>
                            <button id="{$field}_postfiles" href="javascript:void(0);" class=' btn btn-cyan'>开始上传</button>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label"></label>
                    <div class="col-sm-6">
                        <div id="{$field}_ossfile">你的浏览器不支持flash,Silverlight或者HTML5！</div>
                    </div>
                </div>
EOF;
    echo $html;
}



/**
 * 检查权限添加
 * @param $action
 *
 */
function check_create($action,$args = [],$class = 'btn btn-success btn-sm'){

    $module = app('http')->getName();
    $controller = Request::controller(true);
    $count = count(explode('/',$action));
    if($count > 1){
        $url = $module . '/' . $action;
    }else{ //1=的时候
        $url = $module . '/' . $controller . '/' . $action;
    }
    $jump_url = Route::buildUrl($action,$args);
    $ret = (new \app\console\model\Admin())->check_pri($url);
    $name = (new \app\console\model\Privilege())->where('url',$url)->value('pri_name');
    if($ret){
        echo "<a href=\"{$jump_url}\" class=\"{$class}\">{$name}</a>";
    }
}

/**
 * 检查权限修改
 * @param string $class
 * @param $action
 * @param string $args
 * <a href="{:url('update',['id' => $vo.id])}" class="btn btn-info btn-xs"><i class="fa fa-pencil"></i> 编辑 </a>
 */
function check_update($action,$args = [],$class = 'btn btn-info btn-xs',$font = ''){

    $module = app('http')->getName();

    $controller = Request::controller();
    $count = count(explode('/',$action));
    if($count > 1){
        $url = $module . '/' . $action;
    }else{ //1=的时候
        $url = $module . '/' . $controller . '/' . $action;
    }

    $jump_url = Route::buildUrl($action,$args);
    $ret = (new \app\console\model\Admin())->check_pri($url);

    $pri_name = (new \app\console\model\Privilege())->where('url',$url)->value('pri_name');

    $name = empty($font) ? $pri_name : $font;
    if($ret){
        echo "<a href=\"{$jump_url}\" class=\"{$class}\"><i class=\"fa fa-pencil\"></i> {$name}</a>";
    }

}



/**
 * 检查权限删除
 * @param $action
 * @param string $args
 * @param string $class
 * <a onclick="return confirm('确认要删除么?');" href="{:url('destory',['id' => $vo.id])}"  class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i> 删除 </a>
 */
function check_destory($action,$args = [],$class = 'btn btn-info btn-xs'){

    $module = app('http')->getName();
    $controller = Request::controller();//不要true小写
    $count = count(explode('/',$action));
    if($count > 1){
        $url = $module . '/' . $action;
    }else{ //1=的时候
        $url = $module . '/' . $controller . '/' . $action;
    }

    $jump_url = Route::buildUrl($action,$args);
    $ret = (new \app\console\model\Admin())->check_pri($url);

    $name = (new \app\console\model\Privilege())->where('url',$url)->value('pri_name');
    if($ret){
        echo "<a onclick=\"return confirm('确认要删除么?');\" href=\"{$jump_url}\" class=\"{$class}\"><i class=\"fa fa-trash-o\"></i> {$name}</a>";
    }
}

/**
 * @param $action
 * @param string $args
 * @param string $class
 * <a href="#" class="btn btn-primary btn-xs"><i class="fa fa-folder"></i> 查看 </a>
 */
function check_look($action,$args = [],$class = 'btn btn-primary btn-xs'){
    $module = app('http')->getName();
    $controller = Request::controller(true);
    $url = $module . '/' . $controller . '/' . $action;
    $jump_url = Route::buildUrl($action,$args);
    $ret = (new \app\console\model\Admin())->check_pri($url);
    $name = (new \app\console\model\Privilege())->where('url',$url)->value('pri_name');
    if($ret){
        echo "<a href=\"{$jump_url}\" class=\"{$class}\"><i class=\"fa fa-folder\"></i> {$name}</a>";
    }
}

/**
 * @param $table
 * @return mixed
 */
function diy_button($action, $args = [], $data = 'btn btn-primary btn-xs')
{

    $class = "btn {$data['style']} {$data['size']}";
    $module = app('http')->getName();
    $controller = Request::controller(true);
    $url = ltrim(url($action, [],false),'/');
//    $jump_url = Route::buildUrl($action, $args);

    $jump_url = url($action, $args,false);

    $ret = (new \app\console\model\Admin())->check_pri($url);
    $name = (new \app\console\model\Privilege())->where('url', $url)->value('pri_name');

    if ($ret) {
        if($data['a'] == true){
            echo "<a href=\"{$jump_url}\" class=\"{$class}\">{$name}</a>";//<i class="fa fa-align-justify"></i>
        }else{
            $attr = '';
            foreach ($data['attr'] as $k => $v){
                $attr .= ' attr-'.$k.'='.$v;
            }
            echo "<span  class=\"{$class} click_{$action}\" {$attr}>{$name}</span>";
        }

    }
}

/**
 * 审核按钮 1待审核 2成功 3失败
 */
function audit_button($action, $id, $color ='red',$text)
{
    $module = app('http')->getName();
    $controller = Request::controller(true);
    $url = ltrim(url($action, [],false),'/');
    $ret = (new \app\console\model\Admin())->check_pri($url);
    if($color == '3'){
        $class = 'btn btn-danger btn-xs'; //红色
    }
    if($color == '1'){
        $class = 'btn btn-warning btn-xs'; //标黄色
    }
    if($color == '4'){
        $class = 'btn btn-info btn-xs';//浅蓝色
    }
    if($color == '2'){
        $class = 'btn btn-primary btn-xs';//蓝色
    }
    if ($ret) {
        echo "<span  class=\"{$class} click_{$color}\" attr-id=\"{$id}\"> {$text} </span>";
    }
}

function html($content){
    return html_entity_decode($content,ENT_QUOTES, 'UTF-8');
}

function model($table){
    $class =  'app\model\\'.$table;
    return new $class;
}
function db($table){
    $class =  db($table);
    return  $class;
}
//https://daneden.github.io/animate.css/
// <!--<div class="field">-->
//<!--<input class='optional' data-validate-length-range="5,15" type="text" />-->
 //         <!--</div>-->
